package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

/**
 * 主备接入属性处理器
 */
public class MainDeviceAccessAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        super.after(attr, inst, data);

        /**
         * 金融税控融合产品，主备接入默认为是
         */
        String offerInstId = querySceneInstService.getSceneInst(data.getSceneInstId()).getRootInstId();
        KiteOfferInst kiteOfferInst = querySceneInstService.getOfferInst(data.getCustId(), offerInstId);
        String cateId = Objects.nonNull(kiteOfferInst.getAttr("cateId")) ?
            kiteOfferInst.getAttr("cateId").getValue() :
            "";
        if (KiteStringUtils.equalsAny(cateId, "2100956") || KiteStringUtils.equalsAny(cateId, "2100962", "2100957") && KiteStringUtils
            .equals(attr.getFieldName(), "200004006")) {
            attr.setDefaultValue("1_0000106");
        }
    }

}
